define(['app','echarts','echartsGL'],function(app,echarts){return {module: function($scope, $http, eventBusService, httpService, params, configService) {
	if(params.back == undefined){
		$scope.back = true ;
	}
	
	//返回
	$scope.goback = function(){
		window.history.back();
	}
	
	httpService.post(app.urls.unit_selectSchoolAndAttach, {"fk_unit":'self'}, function (data) {
        if ("0000" === data.code) {
            $scope.schoolList = data.data;
            if($scope.schoolList.length>1){$scope.form.attach=true;}else{$scope.form.attach=false;}
        } else {
            alert(data.msg);
        }
    });
	//获取教师学校总数
	httpService.post(app.urls.unit_selectCountAtCenter,{"fk_unit":'self'}, function (data) {
        if ("0000" === data.code) {
            $scope.form.student = data.data.xs;
        } else {
            alert(data.msg);
        }
    });
	$scope.find = function() {
		 //学生-年级
	    httpService.post(app.urls.studentanalysis_selectGrade, {"fk_unit":$scope.form.fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.grade = data.data;
	            $scope.grade.name = [];
	            $scope.grade.value = [];
	            for (var i = 0; i < $scope.grade.length; i++) {
	                $scope.grade.name.push($scope.grade[i].name);
	                $scope.grade.value.push($scope.grade[i].value);
	            }
	            $scope.echartsInitGrade();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitGrade = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_student_fk_grade"));
	        option = {
	        	    xAxis: {
	        	        type: 'category',
	        	        data:$scope.grade.name,
	        	        axisLine:{       
	        	          "show":false

	        	        },
	        	        axisTick:{       
	        	          "show":false
	        	        },
	        	        splitLine: {     
	        	          "show": false
	        	        }
	        	    },
	        	    yAxis: {
	        	        type: 'value',
	        	        show:false,
	        	          axisLine:{       //y轴
	        	          "show":false

	        	        },
	        	        axisTick:{       //y轴刻度线
	        	          "show":false
	        	        },
	        	        splitLine: {     //网格线
	        	          "show": false
	        	        }
	        	    },
	        	    series: [{
	        	        data: $scope.grade.value,
	        	        type: 'bar',
	        	        itemStyle:{
	        	            normal:{
	        	                label:{
	        	                  formatter: "{c}",
	        	                  show: true,
	        	                  position: "top",
	        	                  textStyle: {
	        	                    fontWeight: "bolder",
	        	                    fontSize: "12",
	        	                },
	        	                },
	        	                 //每根柱子颜色设置
	        	                color: function(params) {
	        	                    let colorList = [
	        	                        "#C1232B",
	        	                        "#B5C334",
	        	                        "#FCCE10",
	        	                        "#E87B10",
	        	                        "#277C7B",
	        	                        "#FE8463",
	        	                        "#9e78d1",
	        	                        "#e960b5",
	        	                        "#78d1c4",
	        	                        "#acc65c",
	        	                        "#73c664",
	        	                        "#5a6baa",
	        	                        "#FE8463",
	        	                        "#e7bc82",
	        	                        "#7dcee9",
	        	                        "#ff8c5c",
	        	                    ];
	        	                    return colorList[params.dataIndex];
	        	                }
	        	            }
	        	        }
	        	    }]
	        	};
	        myChart.setOption(option);
	    }
		
		 //学生-性别
	    httpService.post(app.urls.studentanalysis_selectSex, {"fk_unit":$scope.form.fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.stusex = data.data;
	            $scope.echartsInitStuSex();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitStuSex = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_student_sex"));
	        var colorList = ['#cf9ef1', '#9b8bff'];
	        var data = $scope.stusex;
	        var xdata = [];
	        var ydata = [];
	        var sundata = '';
	        for (var i = 0; i < data.length; i++) {
	            xdata.push(data[i].name);
	            ydata.push(data[i].value);
	        }
	
	        function sum(arr) {
	            return eval(arr.join("+"));
	        };
	        sundata = sum(ydata);
	        option = {
	            backgroundColor: "#fff",
	            title: {
	                text: sundata + "人",
	                //subtext:'总平均值(分)',
	                x: 'center',
	                y: 'center',
	                textStyle: {
	                    fontSize: 14,
	                    fontWeight: 'normal',
	                    color: ['#666']
	                },
	                subtextStyle: {
	                    color: '#999',
	                    fontSize: 12
	                },
	            },
	            grid: {
	                bottom: 0,
	                left: 0,
	                right: '10%'
	            },
	            legend: {
	                show: true,
	                orient: 'horizontal',
	                bottom: "bottom",
	                textStyle: {
	                    color: '#999',
	                    fontSize: 12,
	                },
	                data: xdata,
	                icon: 'roundRect'
	            },
	            series: [
	                // 主要展示层的
	                {
	                    radius: ['25%', '51%'],
	                    center: ['50%', '50%'],
	                    type: 'pie',
	                    itemStyle: {
	                        normal: {
	                            color: function (params) {
	                                return colorList[params.dataIndex]
	                            }
	                        }
	                    },
	                    labelLine: {
	                        normal: {
	                            show: true,
	                            length: 15,
	                            length2: 60,
	                            lineStyle: {
	                                color: '#d3d3d3'
	                            },
	                            align: 'right'
	                        },
	                        color: "#000",
	                        emphasis: {
	                            show: true
	                        }
	                    },
	                    label: {
	                        normal: {
	                            formatter: function (params) {
	                                var str = '' + '{rate|' + params.value + '}';
	                                return str
	                            },
	                            padding: [0, -50],
	                            height: 40,
	                            rich: {
	                                nameStyle: {
	                                    fontSize: 12,
	                                    color: "#555",
	                                    align: 'left'
	                                },
	                                rate: {
	                                    fontSize: 12,
	                                    color: "#1ab4b8",
	                                    align: 'left'
	                                }
	                            }
	                        }
	                    },
	                    data: $scope.stusex,
	                },
	                // 边框的设置
	                {
	                    radius: ['47%', '51%'],
	                    center: ['50%', '50%'],
	                    type: 'pie',
	                    label: {
	                        normal: {
	                            show: false
	                        },
	                        emphasis: {
	                            show: false
	                        }
	                    },
	                    labelLine: {
	                        normal: {
	                            show: false
	                        },
	                        emphasis: {
	                            show: false
	                        }
	                    },
	                    animation: false,
	                    tooltip: {
	                        show: false
	                    },
	                    itemStyle: {
	                        normal: {
	                            color: 'rgba(250,250,250,0.5)'
	                        }
	                    },
	                    data: [{
	                        value: 1,
	                    }],
	                }
	            ]
	        };
	        myChart.setOption(option);
	    }
	}
}}});